#ifndef WORLD_BASE_H
#define WORLD_BASE_H
#include <SDL/SDL.h>
#include <vector>

#include "src/utils/joystick.h"
#include "src/utils/raycast.h"
#include "src/utils/settings.h"
#include "src/common/be_frame_limiter.h"
#include "src/common/be_parser.h"
#include "src/graphics/be_camera.h"
#include "src/utils/logbuffer.h"

#include "entity.h"
#include "player.h"
#include "car.h"
#include "map_mesh.h"
#include "race.h"
#include "sc_messageinfo.h"

#include "src/physics/be_physics_system.h"
#include "src/common/be_physics_debug_renderer.h"

// FIXME REMOVE ME AFTER PHYSICS SCENE EXISTS
#include "btBulletDynamicsCommon.h"
#include "BulletSoftBody/btSoftBody.h"
#include "BulletSoftBody/btSoftBodyRigidBodyCollisionConfiguration.h"

#include "src/graphics/be_graphics_system.h"
#include "src/graphics/sc_graphics.h"

#include "src/net/be_net_system.h"

#include <boost/scoped_ptr.hpp>

using namespace std;

struct Task
{
	string name;
	int argi;
	string args;
	short status;
};

class BaseWorld
{
private:
	BeGraphicsSystem m_graphicsSystem;
	BePhysicsSystem m_physicsSystem;
	boost::scoped_ptr<ScGraphics> m_graphics;
	BeNetSystem m_netSystem;

	public:
		BaseWorld();
		virtual ~BaseWorld();

		void physicsDebugDrawWorld()
		{
			m_physicsSystem.debugDrawWorld(m_dynamicsWorld);
		}


		vector<string>	servermessages;
		vector<string>	clientmessages;
		
		virtual void 		playWorld() {};
		virtual void		prepareTaskChain() {};
		virtual void		process( float timeDelta ) {};
		virtual void		draw();
		virtual void		newMessage(const string& msg);
		virtual void		newMessageAllClients(const string& msg);
		virtual int		findClient(unsigned int id);

		// setting shortcuts
			const unsigned int*		server;
			const unsigned int*		headless;
			const unsigned int*		joystickenabled;
			
		// BULLET
			boost::shared_ptr<btDynamicsWorld> m_dynamicsWorld;

			std::vector<Task>		taskchain;
			std::vector<boost::shared_ptr<Entity> >		entities;
			std::vector<boost::shared_ptr<Player> >		players;
			boost::shared_ptr<Player>			me;
			BeCameraPerspective	m_camera;
			BeSceneNode		m_sceneNodeCamera;
			BeCameraPerspective 	m_cameraFollow;
			BeSceneNode		m_sceneNodeCameraFollow;
			boost::shared_ptr<Map>	m_map;



		

		// RAYCAST
// 			Raycast*	raycast;
			btVector3	mouseRayTo;
			castResult	mouseRay;
			bool		mouseRayHit;
			Entity*		mouseRayHitEntity;
		
		// JOYSTICK
		boost::scoped_ptr<Joystick>		joystick;



	protected:

		Settings*		settings;
		BeParser		parseH;

		// setting shortcuts
			const unsigned int*		drawscene;
			const unsigned int*		follow;
			const unsigned int*		camera_follow;
		
		virtual void newLogMessage(const string& msg);
		vector<string> logbufferQueue;


};


#endif
